<%@page import="entity.GroupsLocal"%>
<%@page import="java.util.ArrayList"%>
<%@page import="entity.GroupsLocalHome"%>
<%@page import="transfer.UserRole"%>
<%@page import="transfer.User"%>
<%@page import="entity.UsersLocalHome"%>
<%@page import="entity.UsersLocal"%>
<%@page import="javax.naming.InitialContext"%>
<%
    InitialContext context = new InitialContext();
    UsersLocalHome userHome = (UsersLocalHome) context.lookup("java:comp/env/Users");
    GroupsLocalHome grouphome = (GroupsLocalHome) context.lookup("java:comp/env/Groups");
    User user = ((UsersLocal) userHome.findByPrimaryKey(new Integer(request.getParameter("id")))).getUser();
%>
<div id="user_id" value="<%= request.getParameter("id") %>" class="box" style="width: 600px;">
    <table class="table-admin" rules=all>

        <tr>
            <td colspan="2" style="text-align: left;">View user</td>
        </tr>
        <tr>
            <td>Login</td>
            <td><%=user.getLogin()%></td>
        </tr>
        <tr>
            <td>First name</td>
            <td><%=user.getFirstName()%></td>
        </tr>
        <tr>
            <td>Last name</td>
            <td><%=user.getLastName()%></td>
        </tr>
        <tr>
            <td>Email</td>
            <td><%=user.getEmail()%></td>
        </tr>
        <tr>
            <td>Address</td>
            <td>
                <%=user.getAddress().getCountry() + ", " + user.getAddress().getCity() + ", "
                        + user.getAddress().getStreet() + ", " + user.getAddress().getBuilding()
                        + ", " + user.getAddress().getFlat()%>
            </td>
        </tr>
        <tr>
            <td>Roles</td>
            <td>
                <%
                    for (int j = 0; j < user.getRoles().size(); j++) {
                        UserRole role = (UserRole) user.getRoles().get(j);
                        out.print(role.getNameRole());
                        if (j < user.getRoles().size() - 1) {
                            out.print(", ");
                        }
                    }
                %>
            </td>
        </tr>
        <tr>
            <td>Groups</td>
            <td>
                <%
                    ArrayList grouplist = (ArrayList) grouphome.findByUser(user);
                    for (int k = 0; k < grouplist.size(); k++) {
                        out.println(((GroupsLocal) grouplist.get(k)).getGroup().getNameGroup());
                        if (k < grouplist.size() - 1) {
                            out.print(", ");
                        }
                    }
                %>
            </td>
        </tr>
    </table>
</div>
<div style="position: absolute; top: 150px; right: 50px;"><img src="../images/face.png"/></div>